package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

public interface UserMapper {
    /**
     * 查询数据
     * @param openid
     * @return
     */
    //添加注解来获取用户id
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Select("select * from user where openid = #{openid}")
    User selectByopid(String openid);

    /**
     * 如果是新用户则插入数据
     * @param user1
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user(openid,create_time,name) values (#{openid},#{createTime},#{name})")
    void insert(User user1);

    /**
     * 根据用户id查询用户数据
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User getById(Long userId);
}
